﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace CSharpExt.IO
{
    public class WriterStream : Stream
    {
        #region Private Data

        private TextWriter _writer;

        #endregion

        #region Constructor

        public WriterStream(TextWriter writer)
        {
            _writer = writer;
        }

        #endregion

        #region Interface

        public override void Flush()
        {
            _writer.Flush();
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new NotImplementedException();
        }

        public override void SetLength(long value)
        {
            throw new NotImplementedException();
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            throw new NotImplementedException();
        }

        public override void WriteByte(byte value)
        {
            _writer.Write((char)value);
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            for (int i = 0, j=offset; i < count; i++)
            {
                WriteByte(buffer[j++]);
            }
        }

        public override bool CanRead
        {
            get { return false; }
        }

        public override bool CanSeek
        {
            get { return false; }
        }

        public override bool CanWrite
        {
            get { return true; ; }
        }

        public override long Length
        {
            get { throw new NotImplementedException(); }
        }

        public override long Position
        {
            get { throw new NotImplementedException(); }
            set { throw new NotImplementedException(); }
        }

        #endregion

    }
}
